package org.example.gradleauth.model.factory;

import org.example.gradleauth.model.dto.JwtClaimDto;
import org.example.gradleauth.model.entity.StaffUserDetails;
import gradle.common.core.constants.SecurityConstant;
import org.springframework.security.core.GrantedAuthority;

import java.util.stream.Collectors;

/**
 * 装配工厂
 */
public class AssembleFactory {

    /**
     * 构建JWT Claim对象。
     *
     * @param userDetails 用户详细信息
     * @return 返回构建好的JWT Claim对象
     */
    public static JwtClaimDto buildJwtClaim(StaffUserDetails userDetails) {
        JwtClaimDto jwtClaimDto = new JwtClaimDto();
        jwtClaimDto.setUserId(userDetails.getId());
        jwtClaimDto.setUsername(userDetails.getUsername());
        jwtClaimDto.setAuthorities(userDetails.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.joining(SecurityConstant.DEFAULT_AUTHORITIES_CLAIM_DELIMITER)));
        return jwtClaimDto;


    }

}
